package com.installtime.demo.Interceptor;

import com.installtime.demo.constant.ResultCodeEnums;
import com.installtime.demo.model.Result;
import com.jfinal.aop.Interceptor;
import com.jfinal.aop.Invocation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


/**
 * @Classname GlobalExceptionInterceptor
 * @Description 全局异常处理
 * @Date 6/29/2020 2:04 PM
 * @Created by W.Z
 */
public class GlobalExceptionInterceptor implements Interceptor {

        private static final Logger log = LoggerFactory.getLogger(GlobalExceptionInterceptor.class);


    public void intercept(Invocation inv) {
        log.info("---------------------start interceptor--------------------------");
        try {
            inv.invoke();
        }catch (IllegalArgumentException e){
            log.error("参数异常",e);
            inv.getController().renderJson(Result.failed(ResultCodeEnums.ILLEGAL_PARAM_ERROR.getCode(),e.getMessage()));
        }
        log.info("---------------------end interceptor--------------------------");
    }
}
